/********************************************************************************************************************************
 * 《C ++ Primer》第五版中文版，读书笔记：按照书中的的示例源码和每一个小章节的课后习题，自己动手写代码实现，作为联系和测试。
 * Date: 2024-04-01 17:53
 * Author: dimon.chen 
 * EMali: 1181302388@qq.com 
 * 
 * 章节: 第三章 字符串，向量和数组
 *       3.4 迭代器介绍
 * 
 ********************************************************************************************************************************/


#include <iostream>
#include <string>
#include <vector>
#include <cctype>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;


int main(int argc, char *argv[])
{

    ///
    /// 3.4.1 节练习
    /// 3.21 请使用迭代器重做3.3 节的第一练习
    ///

    //a
    cout << "a" << endl;
    vector<int> v1;
    cout << "size=" << v1.size() << endl;
    for(auto it = v1.begin(); it != v1.end(); it++)
        cout << *it << " " << "";
    cout << endl;

    
    cout << "b" << endl;
    vector<int> v2(10);
    cout << "size=" << v2.size() << endl;
    for(auto it = v2.begin(); it != v2.end(); it++)
        cout << *it << " ";
    cout << endl;
    
    cout << "c" << endl;
    vector<int> v3(10,42);
    cout << "size=" << v3.size() << endl;
    for(auto it=v3.begin(); it != v3.end(); it++)
        cout << *it << " ";
    cout << endl;

    cout << "d" << endl;
    vector<int> v4{10};
    cout << "size=" << v4.size() << endl;
    for(vector<int>::iterator it = v4.begin(); it!=v4.end(); it++)
        cout << *it << " ";
    cout << endl;


    cout << "e" << endl;
    vector<int> v5{10, 42};
    cout << "size=" << v5.size() << endl;
    for(vector<int>::const_iterator it = v5.cbegin(); it != v5.cend(); it++)
        cout << *it << " ";
    cout << endl;


    cout << "f" << endl;
    vector<string> v6{10};
    cout << "size=" << v6.size() << endl;
    for(auto it = v6.begin(); it != v6.end(); it++)
        if((*it).empty())
            cout << "empty" << " ";
        else
            cout << *it << " ";
    cout << endl;


    cout << "g" << endl;
    vector<string> v7{10, "hi"};
    cout << "size=" << v7.size() << endl;
    for(auto it = v7.begin(); it != v7.end(); it++)
        cout << *it << " ";
    cout << endl;

    ///
    /// 3.4.1 节练习
    /// 3.22 修改之前的那个 text 输出的第一段程序，先把 text 的一段都改写为大写然后输出它。
    ///

    vector<string> text{"Hello Joliye, she is kate form the hell", "so you really wantis",
                        "somethigns else", "or ont", "", "so it is reasonable"};

    for(auto it = text.begin(); it != text.end(); it++){
        if(it->empty())
            break;
        
        cout << *it << endl;
        
        for(auto c : (*it))
            cout << (char)toupper(c);
        cout << endl;
    }



    ///
    /// 3.4.1 节练习
    /// 3.23 编写一段程序，创建一个含有10个整数的 vector 对象，然后使用迭代器将所有元素的值都变为原来的两倍，
    ///      输出vector对象的内容，检验程序是否正确
    ///

    vector<int> v9;
    for(int i=0; i<10; i++)
        v9.push_back(i);
    
    for(auto it = v9.begin(); it != v9.end(); it++)
        *it = (*it) * (*it);
    
    for(vector<int>::iterator it = v9.begin(); it != v9.end(); it++){
        cout << *it << " ";
    }
    cout << endl;

}